package site.wtcc.originalfavor.biz;

import lombok.Data;
import site.wtcc.originalfavor.func.exception.ResponseCode;

import java.util.Map;

@Data
public class Result<T> {
    private boolean success;
    private boolean bizSuccess;
    private Integer errCode;
    private String errMsg;
    private String bizErrMsg;
    private Map<String, Object> otherData;
    private T data;

    private Result(boolean success, Integer errCode, String errMsg, T data, Map<String, Object> otherData) {
        this.success = success;
        this.bizSuccess = success;
        this.errCode = errCode;
        this.errMsg = errMsg;
        this.bizErrMsg = errMsg;
        this.data = data;
        this.otherData = otherData;
    }

    private Result(boolean success, boolean bizSuccess, Integer errCode, String errMsg, T data, Map<String, Object> otherData) {
        this.success = success;
        this.bizSuccess = bizSuccess;
        this.errCode = errCode;
        this.errMsg = errMsg;
        this.bizErrMsg = errMsg;
        this.data = data;
        this.otherData = otherData;
    }

    public static <T> Result<T> ofData() {
        return new Result<>(true, null, null, null, null);
    }

    public static <T> Result<T> ofData(T data) {
        return new Result<>(true, null, null, data, null);
    }

    public static <T> Result<T> ofError(Integer errCode, String errMsg) {
        return new Result<>(false, false, errCode, errMsg, null, null);
    }

    public static <T> Result<T> ofError(String errMsg) {
        return new Result<>(true, false, 500, errMsg, null, null);
    }

    public static <T> Result<T> ofError(ResponseCode responseCode) {
        return new Result<>(false, false, responseCode.getCode(), responseCode.getMessage(), null, null);
    }

    public static <T> Result<T> ofError(ResponseCode responseCode, String errMsg) {
        return new Result<>(false, false, responseCode.getCode(), errMsg, null, null);
    }

    public static <T> Result<T> ofBizError(Integer errCode, String errMsg) {
        return new Result<>(true, false, errCode, errMsg, null, null);
    }

    public static <T> Result<T> ofBizError(String errMsg) {
        return new Result<>(true, false, 500, errMsg, null, null);
    }

    public static <T> Result<T> of(Boolean success, Integer errCode, String errMsg, T data) {
        return new Result<>(success, errCode, errMsg, data, null);
    }

    public static <T> Result<T> of(Boolean success, Integer errCode, String errMsg, T data, Map<String, Object> otherData) {
        return new Result<>(success, errCode, errMsg, data, otherData);
    }
}